Skip to main content

Generating QR code for a link

  1. Before you begin, create a Secret API key by following the guidelines in this article.

  2. Get the link ID of the short link you want to edit (follow the steps in this article).

  3. Install prerequisites for requests:

pip install requests

Now everything is ready to run the following snippet. It will create a region targeting rule for a short URL.

  1. Create a file: filename.py/ .js/ .rb. Use the code snippet below.

Please, replace link_idString, API_KEY, FILE_NAME with an appropriate value.

Consider the following parameters:

Parameter nameTypeConstraintsDescription
typestringoptionalFile format: png, svg, pdf
colornumberoptional0xff0000
backgroundColornumberoptional0xff0000
sizenumberoptional6
import requests

url = "https://api.short.io/links/qr/{link_idString}"

import json
payload = json.dumps({"type":"png"})
headers = {
'accept': "application/json",
'content-type': "application/json",
'authorization': "API_KEY"
}

response = requests.request("POST", url, data=payload, headers=headers)

open('FILE_NAME.png', 'wb').write(response.content)
  1. Launch the file.
python filename.py